import request from '@/axios';
import {baseUrl} from '@/config/env';


export const loginByUsername = (userName, password, code, redomStr) => {
    let data = {userName, password, code, redomStr}
    return request({
            url: baseUrl + '/user/login',
            method: 'post',
            meta: {isToken: false},
            data: data
        }
    )
}

export const getUserInfo = () => request({
    url: baseUrl + '/user/getUserInfo',
    method: 'get'
});

export const refeshToken = () => request({
    url: baseUrl + '/user/refreshToken',
    method: 'post'
})

export const getMenu = (type = 0) => request({
    url: baseUrl + '/user/menu/getMenu',
    method: 'get',
    data: {type}
});

export const getTopMenu = () => request({
    url: baseUrl + '/user/menu/getTopMenu',
    method: 'get'
});

export const sendLogs = (list) => request({
    url: baseUrl + '/user/logout',
    method: 'post',
    data: list
})

export const logout = () => request({
    url: baseUrl + '/user/loginOut',
    meta: {
        isToken: true
    },
    method: 'get'
})

export const getUserRoles = (userId = '') => request({
    url: baseUrl + '/user/role/getUserRoles?userId=' + userId,
    method: 'get'
})

export const saveUserRoles = (userId, data) => request({
    url: baseUrl + '/user/role/saveUserRoles/' + userId,
    method: 'post',
    data: data
})

/**
 * 修改当前用户信息
 * @param data
 * @returns {*}
 */
export const updateCurrentUserInfo = (data) => request({
    url: baseUrl + '/user/updateCurrentUserInfo',
    method: 'post',
    data: data
})
/**
 * 修改当前用户密码
 * @param data
 * @returns {*}
 */
export const updateCurrentUserPassword = (data) => request({
    url: baseUrl + '/user/updateCurrentUserPassword',
    method: 'post',
    data: data
})
